package zuk.clipvietfun;

import java.io.File;

import zuk.clipvietfun.getdata.GetDataFromUrl;
import android.os.AsyncTask;
import android.view.View;
import android.widget.RelativeLayout;

public class LoadScreen extends AsyncTask<Void, Void, Boolean>{
	File dir;
	RelativeLayout load_ly;
	public LoadScreen(File dir, RelativeLayout load_ly) {
		this.dir = dir;
		this.load_ly = load_ly;
	}

	@Override
	protected Boolean doInBackground(Void... params) {
		if (!dir.exists()) {
			dir.mkdirs();
		}
		for(int i = 2 ; i <= 6 ; i++){
			if(isCancelled())
				break;
			try {
				String sClip = Const.swTab(i);
				new GetDataFromUrl(sClip,dir).getData();
			} catch (Exception e) {
				return false;
			}
		}
		return true;
	}

	@Override
	protected void onCancelled() {
		load_ly.setVisibility(View.GONE);
		DirAndFile.deleteDir(dir);
		super.onCancelled();
	}

	@Override
	protected void onPostExecute(Boolean result) {
		load_ly.setVisibility(View.GONE);
		super.onPostExecute(result);
	}
}
